export default {
    name: "Index",
    data() {
        return {
            users:[],
            useable: true,
            targetPerson:[],
            tasklog:{
                isConsign:'1',
            },
            dialogFormVisible:false,
            searchForm: {
                startTime: '',
                endTime: '',
            },
            tableData: [],
            pager: {
                page: 0,
                size: 20,
                total: 0
            },
            dialogTitle: '任务',
            entityId: '',
            expireTimeOption: this.checkApplyDate(), //entityForm,
            tasklogs:[],
            user:{},
        }
    },
    computed: {
        height() {
            return `calc(100vh - 320px)`;
        }
    },
    mounted() {
        this.user=JSON.parse(sessionStorage.getItem("user"));
        this.getusers();
        this.getList();
    },
    methods: {
       
        // 修改
        edit: function (item) {
            this.entityId = item.id;
            let taskWorkitemId = item.taskWorkitemId;
            //this.menuList = [];
            // let path = '/proj/roadShowConference';
            let path="";
            if(item.applyTool != null){
              path = item.applyTool;
            }
            let title = '处理任务';
            this.$router.push({
                path: path,
                query: { id: taskWorkitemId }
            });
          /*
        this.menuList.push({
            title: title,
            path: path
        });
      this.$store.dispatch('SET_CLOSE', false);
        sessionStorage.setItem('menuList', window.Qs.stringify(this.menuList));
        this.$store.dispatch('SET_MENU', this.utils.unique(this.menuList, this.menu));*/

        },
        // 获取任务列表
        getList: function () {
            let user = JSON.parse(sessionStorage.getItem("user"));
            let params = {
                page: this.pager.page === 0 ? this.pager.page : this.pager.page - 1,
                size: this.pager.size,
                userId:user.id,
            };
            if(this.searchForm.startTime){
                params.startTime=this.searchForm.startTime
            }
            if(this.searchForm.endTime){
                params.endTime=this.searchForm.endTime
            }
            // this.$api.post(  '/wf/taskLog/todoWork', params).then(res => {
            //     if (res.status === '0') {
            //         console.log(res);
            //         this.tableData = res.data.resContent;
            //         this.pager.total = res.data.total;
            //     }
            // });
            this.$api.formPost('/api/biz/flowMyWork/doGetMyWorks', params).then(res => {
                if (res.retHead.code == '0000000') {
                    console.log(res);
                     this.tableData = res.retBody.resContent;
                     this.pager.total = res.retBody.total;
                }
            });
        },
        startTimeChange() {
            this.searchForm.endTime = '';
        },

        checkApplyDate: function () {
            let self = this;
            return {
                disabledDate(date) {

                    if (self.searchForm.startTime != '') {
                        let t1 = new Date(self.searchForm.startTime).getTime();

                        return date.getTime() <= t1;
                    }


                }
            };
        },
        dateFormatter(row){
           return this.formatDate(row.beginTime,"yyyy-MM-dd HH:mm:ss");
        },
      handleSizeChange(val) {
        this.pager.size = val;
      },
      handleCurrentChange(val) {
        this.pager.page = val;
      },
      //委托
      consign(row){ 
        this.tasklog=JSON.parse(JSON.stringify(row)) ;
        if(row.isConsign){
            this.tasklog.isConsign=row.isConsign;
            if(row.isConsign=='0'){
                this.useable=false;
            }
        }else{
            this.tasklog.isConsign='1';
        }
        
        this.dialogFormVisible=true;
      },

      // 关闭弹窗
      handleFormClose: function () {
        this.tasklog={};  
        this.dialogFormVisible=false;
      },
      //选择委托人
      selectConsignPerson: function (data) {
        if(data.length > 0){
          this.tasklog.consignUser = data[0].value;
        }

      },
      getusers() {
        let params = {};
        this.$api
          .formPost(  "/api/auth/sysuser/doGetList", params)
          .then(res => {
            if (res.retHead.code == "0000000") {
              this.users = res.retBody.list;
            }
          });
      },
      stateChange: function (val) {
        this.tasklog.isConsign = val == true ? "1" : "0";
      },
      doSave(){
         
        this.$api
          .post(  "/api/biz/flowMyWork/saveTaskLog", this.tasklog)
          .then(res => {
            if (res.retHead.code === '0000000') {
              if(res.retBody.status==="0"){
                this.handleFormClose();
                this.getList();
              }else{
                this.$message({
                  type: "error",
                  message: res.retBody.message
                });
              }
                
            }else{
              this.$message({
                type: "error",
                message: res.retHead.message
              });
            }
          });
      },
      //选择复选框事件
      handleSelectionChange(val) {
        this.tasklogs = val;
      },
      //查看进展
      progress(item){
    
        let path = '/flow/taskWorkitem';
        this.$router.push({
            path: path,
            query: { id: item.workflowInstance.id }
        });
      },
    }
}
